package com.java110.mall.cart.cmd.cart;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.storeOrderEngine.StoreOrderEngine;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.storeOrder.StoreOrderReturnPayDto;
import com.java110.utils.exception.CmdException;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @ClassName UnifiedOrderCmd
 * @Description TODO
 * @Author wuxw
 * @Date 2022/5/23 9:17
 * @Version 1.0
 * add by wuxw 2022/5/23
 **/
@Java110Cmd(serviceCode = "/cart/unifiedOrder")
public class UnifiedOrderCmd extends Cmd {

    @Autowired
    private StoreOrderEngine storeOrderEngine;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        Map<String, String> header = cmdDataFlowContext.getReqHeaders();
        //reqJson.put("appId", header.get("app-id"));
        StoreOrderReturnPayDto storeOrderReturnPayDto = storeOrderEngine.unifiedOrder(reqJson);

        cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(ResultVo.CODE_OK, "成功", storeOrderReturnPayDto));

    }
}
